Private Sub test01()
    Dim sql As SelectSql
    Set sql = New SelectSql
    
    Dim col As SelectItem
    Dim colDefine As SqlColumnDefine
    
    ' column
    Set col = New SelectItem
    Set colDefine = SqlExpressionFactory.createSqlColumnDefine("t1", "tekiyo_s_ymd")
    col.Init colDefine
    sql.addSelectItem col
    
    Set col = New SelectItem
    Set colDefine = SqlExpressionFactory.createSqlColumnDefine("t2", "tokuisaki_tanshuku_name")
    col.Init colDefine
    sql.addSelectItem col
    
    Set col = New SelectItem
    Set colDefine = SqlExpressionFactory.createSqlColumnDefine("t3", "sho_bunrui_name")
    col.Init colDefine
    sql.addSelectItem col
    
    ' from
    Dim from1 As DefaultFromItem
    Set from1 = FromItemFactory.createMainRealItem("t1", "sho_seihin_tokuisaki_khn")
    sql.addFrom from1
    
    ' join1
    Dim join1 As DefaultFromItem
    Set join1 = FromItemFactory.createLeftJoinRealItem("t2", "tokuisaki")
    sql.addFrom join1
    
    ' join1-condition1
    Dim condition As SqlCondition
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t2", "tokuisaki_houjin_cd"), _
            SqlExpressionFactory.createSqlColumnDefine("t1", "tokuisaki_cd")
    join1.addCondition condition

    ' join1-condition2
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t2", "tokuisaki_houjin_cd"), _
            SqlExpressionFactory.createStringValue("111111")
    join1.addCondition condition
    
    
    ' join2
    Dim join2 As DefaultFromItem
    Set join2 = FromItemFactory.createLeftJoinRealItem("t3", "cd_tokuisaki_dpt")
    sql.addFrom join2
    
    ' join2-condition1
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t3", "houjin_cd"), _
            SqlExpressionFactory.createSqlColumnDefine("t1", "tokuisaki_cd")
    join2.addCondition condition

    ' join2-condition2
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t3", "dpt_cd"), _
            SqlExpressionFactory.createSqlColumnDefine("t1", "tokuisaki_bunrui_cd")
    join2.addCondition condition
    
    ' join2-condition3
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t3", "nendo"), _
            SqlExpressionFactory.createStringValue("222222")
    join2.addCondition condition
    
    ' where
    ' where-condition1
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t1", "shohin_cd"), _
            SqlExpressionFactory.createStringValue("111111")
    sql.addWhereCondition condition

    ' where-condition2
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t1", "tokuisaki_cd"), _
            SqlExpressionFactory.createStringValue("222222")
    sql.addWhereCondition condition
    

    ' where-condition3---subSelect
    Dim subSelect As SelectSql
    Set subSelect = New SelectSql
    
    Dim subSelectCol As SelectItem
    Dim subSelectFunction As FuncExpression
    Dim subSelectColDefine As SqlColumnDefine
    
    ' where-condition3---subSelect---column
    Set subSelectCol = New SelectItem
    Set subSelectFunction = SqlExpressionFactory.createFunction("MAX")
    Set subSelectColDefine = SqlExpressionFactory.createSqlColumnDefine("", "tekiyo_s_ymd")
    subSelectFunction.addParma subSelectColDefine
    subSelectCol.Init subSelectFunction
    subSelect.addSelectItem col

    ' where-condition3---subSelect---from
    Dim subFrom As DefaultFromItem
    Set subFrom = FromItemFactory.createMainRealItem("", "sho_seihin_tokuisaki_khn")
    subSelect.addFrom subFrom
       
    ' where-condition3---subSelect---where--condition1
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("", "shohin_cd"), _
            SqlExpressionFactory.createStringValue("111111")
    subSelect.addWhereCondition condition
    
    ' where-condition3---subSelect---where--condition2
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_ConditionOperator.COND_AND, _
            SqlExpressionFactory.createSqlColumnDefine("", "tokuisaki_cd"), _
            SqlExpressionFactory.createStringValue("222222")
    subSelect.addWhereCondition condition
    
    ' where-condition3---subSelect---where--condition3
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.LESS_EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("", "tekiyo_s_ymd"), _
            SqlExpressionFactory.createStringValue("20221012")
    subSelect.addWhereCondition condition

    ' where-condition3---subSelect---where--condition4
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.NO_EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("", "kshin_kbn"), _
            SqlExpressionFactory.createStringValue("3")
    subSelect.addWhereCondition condition

    ' where-condition3
    Set condition = New SqlCondition
    condition.Init SqlEnum_ConditionOperator.COND_AND, _
            SqlEnum_CompareOperator.EQUAL, _
            SqlExpressionFactory.createSqlColumnDefine("t1", "tekiyo_s_ymd"), _
            subSelect
    sql.addWhereCondition condition

End Sub

